/**
 * 培训大纲-岗位说明书
 */
<template>
   <VpFileListCard :attachmentList="attachments" @attachmentListEmit="getAttachmentListEmit">
		<template #header>
			<vp-label zh="岗位说明书/附件" en="Position Description/Attachment"/>
		</template>
	</VpFileListCard>
</template>
<script setup lang="ts" name="positionDescriptionTab">
import { onMounted, ref, watch } from 'vue';
import request from '/@/utils/request';
import VpFileListCard from '/@/components/vp/file/VpFileListCard.vue';

	const props = defineProps({
		positionId: {
			type: String
		},
		gwsmsfjglid: {
			type: String
		},
	});

	// 监听岗位id改变，则刷新页面
	watch(()=> props.gwsmsfjglid, ()=>{
		loadDataList();
	})

	// 组件挂载后事件
	onMounted(() => {
		loadDataList()
	})

	const attachments = ref([] as any[]);
	const loading = ref(false);

	// 加载列表数据
	const loadDataList = () => {
		if (props.gwsmsfjglid) {
			loading.value = true;
			request.get('/file/'+props.gwsmsfjglid).then(res => {
				attachments.value = res?.data || []
			}).finally(()=>{
				loading.value = false;
			})
		}
	}

	// 附件新增/删除
	const getAttachmentListEmit = (list: any[]) => {
		attachments.value = list;
		request.post("/training/position/positionDescription/save", {
			id: props.positionId,
			gwsmsfjglid: props.gwsmsfjglid,
			attachments: list,
		}).then(() => {
		}).catch(() => {}).finally(() => {
		})
	}

</script>
